﻿ /////////////////////////////////////////////////////////////////////
// QHsmTst class
import com.troyworks.hsmf.Signal;
import com.troyworks.hsmf.AEvent;

class com.troyworks.hsmf.HsmfETest extends com.troyworks.hsmf.Hsmf
{
	public static var A_SIG : Signal = new Signal (USER_SIG.value + 0, "A_SIG");
	public static var B_SIG : Signal = new Signal (USER_SIG.value + 1, "B_SIG");
	public static var C_SIG : Signal = new Signal (USER_SIG.value + 2, "C_SIG");
	public static var D_SIG : Signal = new Signal (USER_SIG.value + 3, "D_SIG");
	public static var E_SIG : Signal = new Signal (USER_SIG.value + 4, "E_SIG");
	public static var F_SIG : Signal = new Signal (USER_SIG.value + 5, "F_SIG");
	public static var G_SIG : Signal = new Signal (USER_SIG.value + 6, "G_SIG");
	public static var H_SIG : Signal = new Signal (USER_SIG.value + 7, "H_SIG");
	//AEvents
	public static var A_EVT : AEvent = new AEvent (A_SIG);
	public static var B_EVT : AEvent = new AEvent (B_SIG);
	public static var C_EVT : AEvent = new AEvent (C_SIG);
	public static var D_EVT : AEvent = new AEvent (D_SIG);
	public static var E_EVT : AEvent = new AEvent (E_SIG);
	public static var F_EVT : AEvent = new AEvent (F_SIG);
	public static var G_EVT : AEvent = new AEvent (G_SIG);
	public static var H_EVT : AEvent = new AEvent (H_SIG);
	private var timeline:MovieClip;

	public function HsmfETest (tl : MovieClip)
	{
		super (this.onInit);
		trace("HsmfETest");
		timeline = tl;
	}
	/* extended state variable */
	private var __foo : Boolean;
	/*.................................................................*/
	function onInit (e : AEvent):Void
	{
		_global.outText ("top-INIT;");
		this.__foo = false;
		/* initialize extended state variable */
		Q_INIT (s0);
	}
	/*.................................................................*/
	function s0 (e : AEvent):Function
	{
		var sn = "s0-";
		this.__cStateName = sn;
		this.__cStateOpts = [E_EVT];
		if (e != EMPTY_EVT  && e != EMPTY_EVT)
		{
			_global.outText (sn + e);
		}
		switch (e)
		{
			case ENTRY_EVT :
			{
				this.timeline.s0Vis.gotoAndStop (2);
				return null;
			}
			case EXIT_EVT :
			{
				this.timeline.s0Vis.gotoAndStop (1);
				return null;
			}
			case INIT_EVT :
			{
				this.Q_INIT (this.s1);
				return null;
			}
			case E_EVT :
			{
				this.Q_TRAN (this.s211);
				return null;
			}
		}
		return this.s_top;
	}
	/*.................................................................*/
	function s1 (e : AEvent):Function
	{
		var sn = "s1-";
		this.__cStateName = sn;
		this.__cStateOpts = [A_EVT, B_EVT, C_EVT, D_EVT, F_EVT];
		if (e != EMPTY_EVT)
		{
			_global.outText (sn + e);
		}
		switch (e)
		{
			case ENTRY_EVT :
			{
				this.timeline.s1Vis.gotoAndStop (2);
				return null;
			}
			case EXIT_EVT :
			{
				this.timeline.s1Vis.gotoAndStop (1);
				return null;
			}
			//case INIT_EVT :
			//{
				//this.Q_INIT (this.s11);
				//return null;
			//}
			case A_EVT :
			{
				this.Q_TRAN (this.s1);
				return null;
			}
			case B_EVT :
			{
				this.Q_TRAN (this.s11);
				return null;
			}
			case C_EVT :
			{
				this.Q_TRAN (this.s2);
				return null;
			}
			case D_EVT :
			{
				this.Q_TRAN (this.s0);
				return null;
			}
			case F_EVT :
			{
				this.Q_TRAN (this.s211);
				return null;
			}
		}
		return this.s0;
	}
	/*.................................................................*/
	function s11 (e : AEvent):Function
	{
		var sn = "s11-";
		this.__cStateName = sn;
		this.__cStateOpts = [G_EVT, H_EVT, D_EVT];
		if (e != EMPTY_EVT)
		{
			_global.outText (sn + e);
		}
		switch (e)
		{
			case ENTRY_EVT :
			{
				this.timeline.s11Vis.gotoAndStop (2);
				return null;
			}
			case EXIT_EVT :
			{
				this.timeline.s11Vis.gotoAndStop (1);
				return null;
			}
			case D_EVT :
			{
				this.Q_TRAN (this.s1);
				return null;
			}
			case G_EVT :
			{
				this.Q_TRAN (this.s211);
				return null;
			}
			case H_EVT :
			{
				/* internal transition with a guard */
				if (this.__foo)
				{
					/* test the guard condition */
					_global.outText ("s11-Handling H; setting foo to false");
					this.__foo = false;
					return null;
				}
			}
			break;
		}
		return this.s1;
	}
	/*.................................................................*/
	function s2 (e : AEvent):Function
	{
		var sn = "s2-";
		this.__cStateName = sn;
		this.__cStateOpts = [C_EVT, F_EVT];
		if (e != EMPTY_EVT)
		{
			_global.outText (sn + e);
		}
		switch (e)
		{
			case ENTRY_EVT :
			{
				this.timeline.s2Vis.gotoAndStop (2);
				return null;
			}
			case EXIT_EVT :
			{
				this.timeline.s2Vis.gotoAndStop (1);
				return null;
			}
			case INIT_EVT :
			{
				this.Q_INIT (this.s21);
				return null;
			}
			case C_EVT :
			{
				this.Q_TRAN (this.s1);
				return null;
			}
			case F_EVT :
			{
				this.Q_TRAN (this.s11);
				return null;
			}
		}
		return this.s0;
	}
	/*.................................................................*/
	function s21 (e : AEvent):Function
	{
		var sn = "s21-";
		this.__cStateName = sn;
		this.__cStateOpts = [B_EVT, H_EVT];
		if (e != EMPTY_EVT)
		{
			_global.outText (sn + e);
		}
		switch (e)
		{
			case ENTRY_EVT :
			{
				this.timeline.s21Vis.gotoAndStop (2);
				return null;
			}
			case EXIT_EVT :
			{
				this.timeline.s21Vis.gotoAndStop (1);
				return null;
			}
			case INIT_EVT :
			{
				this.Q_INIT (this.s211);
				return null;
			}
			case B_EVT :
			{
				this.Q_TRAN (this.s211);
				return null;
			}
			case H_EVT :
			{
				/* self transition with a guard */

				if ( ! this.__foo)
				{
					_global.outText ("passed gaurd");
					/* test the guard condition */
					this.__foo = true;
					this.Q_TRAN (this.s21);
					/* self transition */
					return null;
				}
				_global.outText ("failed Guard");
			}
			break;
			/* break to return the superstate */
		}
		return this.s2;
	}
	/*.................................................................*/
	function s211 (e : AEvent):Function
	{
		var sn = "s211-";
		this.__cStateName = sn;
		this.__cStateOpts = [D_EVT, G_EVT];
		if (e != EMPTY_EVT)
		{
			_global.outText (sn + e);
		}
		switch (e)
		{
			case ENTRY_EVT :
			{
				this.timeline.s211Vis.gotoAndStop (2);
				return null;
			}
			case EXIT_EVT :
			{
				this.timeline.s211Vis.gotoAndStop (1);
				return null;
			}
			case D_EVT :
			{
				this.Q_TRAN (this.s21);
				return null;
			}
			case G_EVT :
			{
				this.Q_TRAN (this.s0);
				return null;
			}
		}
		return this.s21;
	}
}
